package org.niu.sort;

import javax.swing.*;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

public class ThirdMax {
    public int thirdMax(int[] nums) {
        if(nums.length == 0) return 0;
        Set<Long> s = new HashSet<>();
        for (long num : nums) {
            s.add(num);
        }
        PriorityQueue<Long> q = new PriorityQueue<>(new Comparator<Long>() {
            @Override
            public int compare(Long o1, Long o2) {
                return (int) (o2-o1);
            }
        });
        for (long i : s) {
            q.offer(i);
        }
        if(q.size() < 3){
            return Math.toIntExact (q.peek());
        }
        q.poll();
        q.poll();
        return Math.toIntExact(q.poll());
    }
}
